var app = getApp()
let api = require('../../../api/api.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbar: [{
      name: "收益"
    }, {
      name: "提现"
    }, {
      name: "渠道佣金"
    } ],
    currentTabsIndex: 0,
  },
  navbar: function (e) {
    console.log(e)
    var index = e.currentTarget.dataset.index
    if (index == 0) {
      var param = {}
      param.id = this.data.data.id
      param.mobile = this.data.data.mobile
      api.transaction(param, res => {
        console.log(res)
        this.setData({
          indexData: res.data.result
        })
      })
    }
    if (index == 1) {
      this.setData({
        indexData:{}
      })
      var param = {}
      param.id = this.data.data.id
      param.mobile = this.data.data.mobile
      api.embody(param, res => {
        console.log(res)
        this.setData({
          indexData: res.data.result
        })
      })
    }
    if (index == 2) {
      this.setData({
        indexData: {}
      })
      var param = {}
      param.id = this.data.data.id
      param.mobile = this.data.data.mobile
      api.rebatelist(param, res => {
        console.log(res)
        this.setData({
          indexData: res.data.result
        })
      })
    }
    this.setData({
      currentTabsIndex: index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (data) {
    if(data.index == 0){
      var param = {}
      param.id = data.id
      param.mobile = data.mobile
      api.transaction(param, res => {
        console.log(res)
        this.setData({
          indexData: res.data.result,
        })
      })
    }
    else if(data.index == 1){
      var param = {}
      param.id = data.id
      param.mobile = data.mobile
      api.embody(param, res => {
        console.log(res)
        this.setData({
          indexData: res.data.result
        })
      })
    }else if(data.index == 2){
      var param = {}
      param.id = data.id
      param.mobile = data.mobile
      api.rebatelist(param, res => {
        console.log(res)
        this.setData({
          indexData: res.data.result,
          level: app.globalData.userInerInfo.level
        })
      })
    }
    this.setData({
      data: data,
      currentTabsIndex: data.index,
      level: app.globalData.userInerInfo.level
    })
  }
})